package com.example.controller;

import com.example.Utils.UserHolder;
import com.example.model.Checkin;
import com.example.model.Result;
import com.example.model.User;
import com.example.modelDTO.CheckInDTO;
import com.example.modelDTO.converter.CheckInConverter;
import com.example.service.ICheckinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Hello
 * @since 2024-07-12
 */
@RestController
@RequestMapping("/checkin")
public class CheckinController {
    @Autowired
    ICheckinService iCheckinService;
    @Autowired
    CheckInConverter checkInConverter;
    @GetMapping("/checkin")
    public Result<String> checkin(){
        User loginUser = UserHolder.getUser();
        Integer userId = loginUser.getUserId();
        Boolean aBoolean = iCheckinService.checkIn(userId);
        if(aBoolean) return Result.success("成功");
        return Result.fail("失败");
    }
    @GetMapping("/getCheckInInfo")
    public Result<CheckInDTO> getCheckInInfo(){
        User loginUser = UserHolder.getUser();
        Integer userId = loginUser.getUserId();
        Checkin checkInInfo = iCheckinService.getCheckInInfo(userId);
        if(checkInInfo == null) return Result.fail("失败");
        CheckInDTO checkInDTO = checkInConverter.sourceToTarget(checkInInfo);
        return Result.success(checkInDTO);
    }
}
